#include <wx/wx.h>
#include "MainFrame.h"
#include "EditorCore/Tools/SelectTool.h"
#include "EditorCore/Tools/MoveTool.h"
#include "Tools/CircleAddTool.h"
#include "Tools/PolygonAddTool.h"

void MainFrame::ActivateTool() {
	if( m_tool && m_document ) {
		editor_core::IAction* action = m_tool->Activate();
		if( action != 0 )
			m_document->GetHistory()->Do( action );
	}
}

void MainFrame::DeactivateTool() {
	if( m_tool && m_document ) {
		editor_core::IAction* action = m_tool->Deactivate();
		if( action != 0 )
			m_document->GetHistory()->Do( action );
	}
}

void MainFrame::OnToolSelectSelected( wxCommandEvent& event ) {
	if( m_document ) {
		DeactivateTool();
		delete m_tool;
		m_tool = new editor_core::SelectTool( m_document );
		ActivateTool();
	}
	else {
		event.Skip();
	}
}

void MainFrame::OnToolMoveSelected( wxCommandEvent& event ) {
	if( m_document ) {
		DeactivateTool();
		delete m_tool;
		m_tool = new editor_core::MoveTool( m_document );
		ActivateTool();
	}
	else {
		event.Skip();
	}
}

void MainFrame::OnToolCreateCircle( wxCommandEvent& event ) {
	if( m_document ) {
		DeactivateTool();
		delete m_tool;
		m_tool = new CircleAddTool( m_document->GetBodyEntity() );
		ActivateTool();
	}
	else {
		event.Skip();
	}
}

void MainFrame::OnToolCreatePolygon( wxCommandEvent& event ) {
	if( m_document ) {
		DeactivateTool();
		delete m_tool;
		m_tool = new PolygonAddTool( m_document->GetBodyEntity() );
		ActivateTool();
	}
	else {
		event.Skip();
	}
}
